export default {
	data() {
		return {
			curData: {},
			modalTitle:"",
			modalText: ""
		}
	},
	methods: {
		//确认对话框点击确定触发
		onModalConfirm() {
			//根据弹出对话框时定义的modalConfirmFn决定执行事件
			this.$util.throttle(async () => {
				this[this.modalConfirmFn]();
			})
		},
		
		//取消订单弹窗确认
		cancelOrder(data) {
			console.log(data)
			this.modalTitle="取消订单";
			this.modalText = '您是否确定要取消订单';
			this.modalTips="";
			this.modalPrice={};
			this.modalConfirmFn = 'cancelOrderConfirm';
			this.curData = data;
			this.$refs.mixModal.open();
		},
		//取消订单提交
		async cancelOrderConfirm() {
			const res = await this.$request('order/cancelOrder', {
				uid: uni.getStorageSync('uid'),
				orderNumber: this.curData.id
			}, {
				showLoading: true
			})
			if (res.result == 0) {
				this.userComPage()
			}
		},
		//删除订单弹窗确认
		deleteOrder(data) {
			console.log(data)
			this.modalTitle="删除订单";
			this.modalText = '您是否确定要删除订单';
			this.modalTips="";
			this.modalPrice={};
			this.modalConfirmFn = 'deleteOrderConfirm';
			this.curData = data;
			this.$refs.mixModal.open();
		},
		//删除订单提交
		async deleteOrderConfirm() {
			const res = await this.$request('order/cancelOrder', {
				uid: uni.getStorageSync('uid'),
				orderNumber: this.curData.id
			}, {
				showLoading: true
			})
			if (res.result == 0) {
				this.userComPage()
			}
		},
		//确认收货 弹窗确认
		confirmReceipt(data) {
			this.modalTitle="确认收货";
			this.modalPrice={};
			this.modalTips="";
			this.modalText = '请确保您已收到商品，并检查无损后再确认收货';
			this.modalConfirmFn = 'confirmReceiptConfirm';
			this.curData = data;
			console.log(this.curData)
			this.$refs.mixModal.open();
		},
		//  确认收货
		async confirmReceiptConfirm() {
			const data = {
				uid: uni.getStorageSync('uid'),
				orderNumber: this.curData.id
			}
			const res = await this.$request('order/querenShouhuo', data);
			this.$util.msg(res.resultNote);
			if (res.result == 0) {
				this.userComPage()
			}
		},
		//  会员支付  余额支付
		async payByBalance(data){
			data.uid = uni.getStorageSync('uid');
			const res=await this.$request('pay/balance-pay',data,{showLoading:true});
			if(res.result==0){
				uni.redirectTo({
					url:`/pages/order/paysuccess?id=${data.orderId}`
				})
			}else{
				this.$util.msg(res.resultNote);
			}
		},
		//支付订单
		async payByWx(data) {
			data.uid = uni.getStorageSync('uid');
			const res = await this.$request("pay/wechat-pay", data, {
				showLoading: true
			});
			if (res.result == 0) {
				this.PaySingData(res.body,data.orderId);
			} else {
				this.$util.msg(res.resultNote)
			}
		},
		PaySingData(data,orderId) {
			console.log(data)
			uni.requestPayment({
				timeStamp: data.timeStamp,
				nonceStr: data.nonceStr,
				package: data.package,
				signType: data.signType,
				paySign: data.paySign,
				success(res) {
					uni.redirectTo({
						url:`/pages/order/paysuccess?id=${orderId}`
					})
				},
				fail(res) {
		           
				}
			});
		},
		userComPage() {
			if (this.curData.type == 'list') {
				this.refresh();
			} else {
				uni.navigateBack()
			}
		}
		
	}
}
